package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Dingdanxinxi;
import com.example.exception.CustomException;
import com.example.service.DingdanxinxiService;
import com.example.vo.DingdanxinxiVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("dingdanxinxiService")
public class DingdanxinxiServiceImpl extends ServiceImpl<DingdanxinxiDao, Dingdanxinxi> implements DingdanxinxiService {

    @Resource
    private DingdanxinxiDao dingdanxinxiDao;

    public Dingdanxinxi add(Dingdanxinxi dingdanxinxi) {
		
	   //youquchong1
        dingdanxinxi.setAddtime(new Date());
        dingdanxinxiDao.insert(dingdanxinxi);
        return dingdanxinxi;
    }
	
	
	
    public void delete(Long id) {
        dingdanxinxiDao.deleteById(id);
    }
	

    public void update(Dingdanxinxi dingdanxinxi) {
        //youquchong2
        dingdanxinxiDao.updateById(dingdanxinxi);
    }
	
	public void updateByzhujian(Dingdanxinxi dingdanxinxi) {
        LambdaQueryWrapper<Dingdanxinxi> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtils.isNotEmpty(dingdanxinxi.getYonghuming()), Dingdanxinxi::getYonghuming,dingdanxinxi.getYonghuming());

        dingdanxinxiDao.update(dingdanxinxi, wrapper);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return dingdanxinxiDao.daochuexcel();
    }

    @Override
    public Dingdanxinxi findById(Integer id) {
        return dingdanxinxiDao.selectById(id);
    }
	
	@Override
    public Dingdanxinxi getByzhujian(String zhujian) {
        return dingdanxinxiDao.getByzhujian(zhujian);
    }

    public DingdanxinxiVo findPage(DingdanxinxiVo dingdanxinxiVo) {
        LambdaQueryWrapper<Dingdanxinxi> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getMingcheng()), Dingdanxinxi::getMingcheng,dingdanxinxiVo.getMingcheng());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getZhongzhiwu()), Dingdanxinxi::getZhongzhiwu,dingdanxinxiVo.getZhongzhiwu());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getYuyueriqi()), Dingdanxinxi::getYuyueriqi,dingdanxinxiVo.getYuyueriqi());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getDanjia()), Dingdanxinxi::getDanjia,dingdanxinxiVo.getDanjia());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getYonghuming()), Dingdanxinxi::getYonghuming,dingdanxinxiVo.getYonghuming());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getXingming()), Dingdanxinxi::getXingming,dingdanxinxiVo.getXingming());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getShouji()), Dingdanxinxi::getShouji,dingdanxinxiVo.getShouji());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getJinshu()), Dingdanxinxi::getJinshu,dingdanxinxiVo.getJinshu());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getZongjine()), Dingdanxinxi::getZongjine,dingdanxinxiVo.getZongjine());        wrapper.like(ObjectUtils.isNotEmpty(dingdanxinxiVo.getIssh()), Dingdanxinxi::getIssh,dingdanxinxiVo.getIssh());        
		wrapper.orderByDesc(Dingdanxinxi::getId);
        Page<Dingdanxinxi> page = new Page<>(dingdanxinxiVo.getCurrent(),dingdanxinxiVo.getCurrentNum());
        dingdanxinxiDao.selectPage(page,wrapper);
        List<Dingdanxinxi> dingdanxinxis = page.getRecords();
        dingdanxinxiVo.setList(dingdanxinxis);
        dingdanxinxiVo.setPages(page.getPages());
        dingdanxinxiVo.setTotal(page.getTotal());
        dingdanxinxiVo.setCurrent(page.getCurrent());
        dingdanxinxiVo.setCurrentNum(page.getSize());
        return dingdanxinxiVo;
    }

    @Override
    public void deleteList(List<Dingdanxinxi> list) {
        List<Integer> ids =  list.stream().map(Dingdanxinxi::getId).collect(Collectors.toList());
        dingdanxinxiDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
